words = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,

}


def isp(n):
    if n <= 1:
        return False
    for i in range(2, int(n * 0.5) + 1):
        if n % i == 0:
            return False
    return True


def fcp(n):
    st = 1

    while True:

        if isp(n + st):
            return n + st

        if isp(n - st):
            return n - st

        st += 1


input_words = input().split()

if len(input_words) != 3:
    print("Wrong input")
else:
    try:
        number = words[input_words[0]] * 100 + words[input_words[1]] * 10 + words[
            input_words[2]]
        if 100 <= number <= 999:
            print(fcp(number))
        else:
            print('Wrong input')
    except KeyError:
        print("Wrong input")